package org.example.demo1;

/**
 * @author Gong.Yang
 */
public class DemoRunnableToBlocked {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized (lock) {
                int i = 0;
                System.out.println("线程1开始执行，进入阻塞状态");
                while (true) {
                    i++;
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized (lock) {
                System.out.println("线程2开始执行");
            }
        });

        thread1.start();
        Thread.sleep(500);
        System.out.println("线程1状态：" + thread1.getState());
        thread2.start();
        Thread.sleep(500);
        System.out.println("线程2状态：" + thread2.getState());

        thread1.join();
        thread2.join();


    }
}
